package com.letian.web.controller.record;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.letian.common.annotation.Log;
import com.letian.common.core.controller.BaseController;
import com.letian.common.core.domain.AjaxResult;
import com.letian.common.enums.BusinessType;
import com.letian.record.domain.RecordGenealogy;
import com.letian.record.service.IRecordGenealogyService;
import com.letian.common.utils.poi.ExcelUtil;
import com.letian.common.core.page.TableDataInfo;

/**
 * 族谱Controller
 * 
 * @author bmz
 * @date 2025-07-20
 */
@RestController
@RequestMapping("/record/genealogy")
public class RecordGenealogyController extends BaseController
{
    @Autowired
    private IRecordGenealogyService recordGenealogyService;

    /**
     * 查询族谱列表
     */
    //@PreAuthorize("@ss.hasPermi('record:genealogy:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordGenealogy recordGenealogy)
    {
        startPage();
        List<RecordGenealogy> list = recordGenealogyService.selectRecordGenealogyList(recordGenealogy);
        return getDataTable(list);
    }

    /**
     * 导出族谱列表
     */
    //@PreAuthorize("@ss.hasPermi('record:genealogy:export')")
    @Log(title = "族谱", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordGenealogy recordGenealogy)
    {
        List<RecordGenealogy> list = recordGenealogyService.selectRecordGenealogyList(recordGenealogy);
        ExcelUtil<RecordGenealogy> util = new ExcelUtil<RecordGenealogy>(RecordGenealogy.class);
        util.exportExcel(response, list, "族谱数据");
    }

    /**
     * 获取族谱详细信息
     */
    //@PreAuthorize("@ss.hasPermi('record:genealogy:query')")
    @GetMapping(value = "/{genealogyId}")
    public AjaxResult getInfo(@PathVariable("genealogyId") Long genealogyId)
    {
        return success(recordGenealogyService.selectRecordGenealogyByGenealogyId(genealogyId));
    }

    /**
     * 新增族谱
     */
    //@PreAuthorize("@ss.hasPermi('record:genealogy:add')")
    @Log(title = "族谱", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordGenealogy recordGenealogy)
    {
        recordGenealogy.setCreateBy(getUsername());
        return toAjax(recordGenealogyService.insertRecordGenealogy(recordGenealogy));
    }

    /**
     * 修改族谱
     */
    //@PreAuthorize("@ss.hasPermi('record:genealogy:edit')")
    @Log(title = "族谱", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordGenealogy recordGenealogy)
    {
        recordGenealogy.setUpdateBy(getUsername());
        return toAjax(recordGenealogyService.updateRecordGenealogy(recordGenealogy));
    }

    /**
     * 删除族谱
     */
    //@PreAuthorize("@ss.hasPermi('record:genealogy:remove')")
    @Log(title = "族谱", businessType = BusinessType.DELETE)
	@DeleteMapping("/{genealogyIds}")
    public AjaxResult remove(@PathVariable Long[] genealogyIds)
    {
        return toAjax(recordGenealogyService.deleteRecordGenealogyByGenealogyIds(genealogyIds));
    }
}
